import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/router/router.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/share.dart';

typedef ShareCallback(SharePlatform platform);

class ShareBottomSheet extends StatelessWidget {
  ShareCallback _shareCallback;

  ShareBottomSheet({ShareCallback callback}) {
    this._shareCallback = callback;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        height: ScreenAdapter.height(360),
        decoration: BoxDecoration(
          color: ThemeColors.colorType11,
          // borderRadius: BorderRadius.only(
          //     topLeft: Radius.circular(ScreenAdapter.width(100)),
          //     topRight: Radius.circular(ScreenAdapter.width(10))), //
        ),
        child: _initBody(context));
  }

  Widget _initBody(BuildContext context) {
    return Column(mainAxisSize: MainAxisSize.min, children: [
      Container(
          height: ScreenAdapter.height(120),
          alignment: Alignment.center,
          child: Text("—— 分享到 ——",
              style: TextStyle(
                  color: ThemeColors.colorType1,
                  fontSize: ScreenAdapter.sp(28)))),
      Expanded(
          child: Row(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
            _getItem("微信好友", "weixing.png", () {
              LRouter.navigatorCtx(context).pop();
              if (_shareCallback != null) {
                _shareCallback(SharePlatform.wechcat);
              }
            }),
            _getItem("朋友圈", "friends.png", () {
              LRouter.navigatorCtx(context).pop();
              if (_shareCallback != null) {
                _shareCallback(SharePlatform.wechatLine);
              }
            }),
            // _getItem("QQ好友", "qq.png", () {
            //   LRouter.navigatorCtx(context).pop();
            //   if (_shareCallback != null) {
            //     _shareCallback(SharePlatform.qq);
            //   }
            // }),
          ])),
      Container(
          height: ScreenAdapter.height(90),
          width: double.infinity,
          color: ThemeColors.colorWhite,
          child: FlatButton(
              onPressed: () {
                LRouter.navigatorCtx(context).pop();
              },
              child: Text("取消",
                  style: TextStyle(
                      color: ThemeColors.colorType1,
                      fontSize: ScreenAdapter.sp(30)))))
    ]);
  }

  /// Item
  Widget _getItem(String title, String image, GestureTapCallback callback) {
    return IntrinsicHeight(
        child: GestureDetector(
            onTap: callback,
            child: Column(children: [
              Image.asset(RPath.imgPath + image,
                  width: ScreenAdapter.width(90),
                  height: ScreenAdapter.width(90)),
              Text(title,
                  style: TextStyle(
                      color: ThemeColors.colorType1,
                      fontSize: ScreenAdapter.sp(25)))
            ])));
  }
}
